<#include "/macro.include"/>
<#assign className = table.classNameBo>
<#assign tableRemarks = table.remarks>
<#assign classNameLower = className?uncap_first>
$(function(){
	var oTable = $('#list').dataTable({
		"aoColumnDefs" : [ {
			"aTargets" : [ 0 ]
		} ],
		"bFilter": false,//搜索栏
		"bSort" : false, // 排序功能
		"aaSorting" : [ [ 0, 'asc' ] ],
		"iDisplayLength":15,
		"bProcessing" : false, // 显示正在处理提示信息
		"bServerSide" : true, // 从服务器获取数据
		'bLengthChange': false, //是否允许自定义每页显示条数.
		"bDestroy":true,//重新调用插件
		"sAjaxSource" : ctx + "/${module}/${classNameLower}/search",// 提供数据url
		"fnServerData" : function(sSource, aoData, fnCallback) {

		},
		"aoColumns" :makeCollomns(),
		 "fnRowCallback" : function(nRow, aData, iDisplayIndex) {
			 return nRow;
		 },
		"sPaginationType" : "bootstrap_full_number",// 分页显示格式
		"oLanguage" : {
			"sLengthMenu" : "每页显示 _MENU_ 条记录",
			"sZeroRecords" : " ",
			"sInfo" : "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
			"sInfoEmpty" : "抱歉，暂无数据",
			"sInfoFiltered" : "(从 _MAX_ 条数据中检索)",
			"sSearch" : "搜索",
			"oPaginate" : {
				"sFirst" : "首页",
				"sPrevious" : "前一页",
				"sNext" : "后一页",
				"sLast" : "尾页",
				"sZeroRecords" : "没有检索到数据",
				"sProcessing" : "正在加载中......"
			}
		}
	});

	jQuery('#archive_wrapper .dataTables_filter input').addClass(
			"form-control input-small"); // modify
	// table
	// search
	// input
	jQuery('#archive_wrapper .dataTables_length select').addClass(
			"form-control input-small"); // modify
	// table
	// per
	// page
	// dropdown
	jQuery('#archive_wrapper .dataTables_length select').select2(); // initialize
	// select2
	// dropdown

	$('#asset_column_toggler input[type="checkbox"]').change(function() {
		/*
		 * Get the DataTables object again - this is not a recreation, just
		 * a get of the object
		 */
		var iCol = parseInt($(this).attr("data-column"));
		var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
		oTable.fnSetColumnVis(iCol, (bVis ? false : true));
	});

	$('#search-btn').click(function() {
		$("#errormsg").html('');
		$("#errordiv").hide();
		oTable.fnDraw();
	});

});

function makeCollomns(){
	return  [
		<#list table.columns as column>
	{
		"mDataProp":"${column.columnNameFirstLower}",
//                "sType" : "string",
//                "sClass": "center",
//                "sWidth" : "5%",
//                "visible": false
	},
		</#list>
	{
		data: function (e) {
			var htmstr="";
			htmstr+='<span class="ratinglistdiv" value="'+e.rating+'"></span><span class="hintlist"></span>';
			return htmstr;
		}
	},
	{
		data: function (e) {
			var htmstr="";
			htmstr+='<a title="查看" href="javascript:;" onclick="show('+e.id+')"><i class="fa fa-eye"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;';
			if(perUpdate){
				htmstr+='<a title="修改" href="javascript:;" onclick="preedit('+e.id+','+e.type+')"><i class="fa fa-edit"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;';
			}
			if(perDelete){
				htmstr+='<a title="删除"  href="javascript:;" onclick="del('+e.id+')"><i class="fa fa-trash-o"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;';
			}
			if(perUpdate){
				htmstr+='<a title="排序"  href="javascript:;" onclick="preeditweight('+e.id+')"><i class="fa fa-unsorted"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;';
			}
			return htmstr;
		}
	}
	];
}

function list(){
	$.ajax({
		url :  ctx+"/${module}/${classNameLower}/ajax/list",
		type : 'post',
		dataType : 'json',
		data : $("#savefrom").serialize(),
		async: false,
		success : function(data){

		}
	});
}

function update(){
	$.ajax({
		url :  ctx+"/${module}/${classNameLower}/ajax/update",
		type : 'post',
		dataType : 'json',
		data : $("#savefrom").serialize(),
		async: false,
		success : function(data){

		}
	});
}

function save(){
	$.ajax({
		url :  ctx+"/${module}/${classNameLower}/ajax/save",
		type : 'post',
		dataType : 'json',
		data : $("#savefrom").serialize(),
		async: false,
		success : function(data){

		}
	});
}

function del(){
	$.ajax({
		url :  ctx+"/${module}/${classNameLower}/ajax/delete",
		type : 'post',
		dataType : 'json',
		data : $("#savefrom").serialize(),
		async: false,
		success : function(data){

		}
	});
}